// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    avatarUrl:"/pages/images/avatar.jpg",
    userName:"王小明",
    contentList: [
      {
        title: "海洋生物研究",
        desc: "走进神秘的深海世界，了解深海生物的独特生存之境。",
        views: "1.8万"
      },
      {
        title: "黑洞的形成与演化",
        desc: "揭秘宇宙中最神秘的天体现象：探索黑洞的形成过程和演化规律。",
        views: "2.3万"
      },
      {
        title: "地球板块运动",
        desc: "地球板块运动的奥秘，了解地震与火山的形成原理。",
        views: "1.5万"
      }
    ],
    character:[
      {
        name:"侯德榜",
        picPath:"/pages/images/hou.jpg"
      },
      {
        name:"陈景润",
        picPath:"/pages/images/chen.jpg"
      },
      {
        name:"卢耀如",
        picPath:"/pages/images/lu.jpg"
      },
      {
        name:"张钹",
        picPath:"/pages/images/zhang.jpg"
      },
      {
        name:"黎念之",
        picPath:"/pages/images/li.jpg"
      },
      {
        name:"王仁",
        picPath:"/pages/images/wang.jpg"
      },
      {
        name:"沈元",
        picPath:"/pages/images/shen.jpg"
      },
      {
        name:"高由禧",
        picPath:"/pages/images/gao.jpg"
      },
      {
        name:"郭令辉",
        picPath:"/pages/images/guo.jpg"
      }
    ]
  },
  navToCharacter(event){
    const imgId = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: `../character0/character0?id=${imgId}`
    })
  },
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    const { nickName } = this.data.userInfo
    this.setData({
      "userInfo.avatarUrl": avatarUrl,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  onInputChange(e) {
    const nickName = e.detail.value
    const { avatarUrl } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  getUserProfile() {
    wx.getUserProfile({
      desc: '用于显示你的用户名', 
      success: (res) => {
        console.log(res)
        this.setData({
          avatarUrl:res.userInfo.avatarUrl,
          userName:res.userInfo.nickName,
        })
      }
    })
  },
})
